package tulingxueyuan117;

import com.sun.org.apache.bcel.internal.generic.RET;

/**
 * Author: Zhang Dongwei
 * Date: 2022/5/25 22:01
 * 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
 * /**
 *  * Definition for singly-linked list.
 *  * public class ListNode {
 *  *     int val;
 *  *     ListNode next;
 *  *     ListNode() {}
 *  *     ListNode(int val) { this.val = val; }
 *  *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 *  * }
 */
public class p16_翻转链表_206 {

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);
        ListNode listNode3 = new ListNode(4);
        ListNode listNode4 = new ListNode(5);
        listNode.next = listNode1;
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;

        ListNode res = reverseList(listNode);
        System.out.println(res);
        while (res.next != null){
            System.out.println(res.val);
        }
    }

    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public static ListNode reverseList1(ListNode head) {
        if(head == null) return null;
        ListNode h = head;
        ListNode res = null;
        ListNode old = null;
        while (h != null){
            ListNode curr = h;
            res = curr;
            old = res;
            res.next = old;
            h = h.next;
        }
        return old;
    }

    public static ListNode reverseList(ListNode head) {
        if(head == null) return null;

        return null;
    }

}
